<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.1.5 - src/lmem.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - lmem.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.1.5</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">14</td>
            <td class="headerCovTableEntry">21</td>
            <td class="headerCovTableEntryLo">66.7 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:15</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $
<span class="lineNum">       3 </span>            : ** Interface to Memory Manager
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span>            : #include &lt;stddef.h&gt;
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #define lmem_c
<span class="lineNum">      11 </span>            : #define LUA_CORE
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : #include &quot;ldebug.h&quot;
<span class="lineNum">      16 </span>            : #include &quot;ldo.h&quot;
<span class="lineNum">      17 </span>            : #include &quot;lmem.h&quot;
<span class="lineNum">      18 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      19 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span>            : 
<span class="lineNum">      22 </span>            : 
<span class="lineNum">      23 </span>            : /*
<span class="lineNum">      24 </span>            : ** About the realloc function:
<span class="lineNum">      25 </span>            : ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
<span class="lineNum">      26 </span>            : ** (`osize' is the old size, `nsize' is the new size)
<span class="lineNum">      27 </span>            : **
<span class="lineNum">      28 </span>            : ** Lua ensures that (ptr == NULL) iff (osize == 0).
<span class="lineNum">      29 </span>            : **
<span class="lineNum">      30 </span>            : ** * frealloc(ud, NULL, 0, x) creates a new block of size `x'
<span class="lineNum">      31 </span>            : **
<span class="lineNum">      32 </span>            : ** * frealloc(ud, p, x, 0) frees the block `p'
<span class="lineNum">      33 </span>            : ** (in this specific case, frealloc must return NULL).
<span class="lineNum">      34 </span>            : ** particularly, frealloc(ud, NULL, 0, 0) does nothing
<span class="lineNum">      35 </span>            : ** (which is equivalent to free(NULL) in ANSI C)
<span class="lineNum">      36 </span>            : **
<span class="lineNum">      37 </span>            : ** frealloc returns NULL if it cannot create or reallocate the area
<span class="lineNum">      38 </span>            : ** (any reallocation to an equal or smaller size cannot fail!)
<span class="lineNum">      39 </span>            : */
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span>            : 
<span class="lineNum">      42 </span>            : 
<span class="lineNum">      43 </span>            : #define MINSIZEARRAY    4
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span>            : 
<span class="lineNum">      46 </span><span class="lineCov">      16976 : void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,</span>
<span class="lineNum">      47 </span>            :                      int limit, const char *errormsg) {
<span class="lineNum">      48 </span>            :   void *newblock;
<span class="lineNum">      49 </span>            :   int newsize;
<span class="lineNum">      50 </span><span class="lineCov">      16976 :   if (*size &gt;= limit/2) {  /* cannot double it? */</span>
<span class="lineNum">      51 </span><span class="lineNoCov">          0 :     if (*size &gt;= limit)  /* cannot grow even a little? */</span>
<span class="lineNum">      52 </span><span class="lineNoCov">          0 :       luaG_runerror(L, errormsg);</span>
<span class="lineNum">      53 </span><span class="lineNoCov">          0 :     newsize = limit;  /* still have at least one free place */</span>
<span class="lineNum">      54 </span>            :   }
<span class="lineNum">      55 </span>            :   else {
<span class="lineNum">      56 </span><span class="lineCov">      16976 :     newsize = (*size)*2;</span>
<span class="lineNum">      57 </span><span class="lineCov">      16976 :     if (newsize &lt; MINSIZEARRAY)</span>
<span class="lineNum">      58 </span><span class="lineCov">       7793 :       newsize = MINSIZEARRAY;  /* minimum size */</span>
<span class="lineNum">      59 </span>            :   }
<span class="lineNum">      60 </span><span class="lineCov">      16976 :   newblock = luaM_reallocv(L, block, *size, newsize, size_elems);</span>
<span class="lineNum">      61 </span><span class="lineCov">      16976 :   *size = newsize;  /* update only when everything else is OK */</span>
<span class="lineNum">      62 </span><span class="lineCov">      16976 :   return newblock;</span>
<span class="lineNum">      63 </span>            : }
<span class="lineNum">      64 </span>            : 
<span class="lineNum">      65 </span>            : 
<span class="lineNum">      66 </span><span class="lineNoCov">          0 : void *luaM_toobig (lua_State *L) {</span>
<span class="lineNum">      67 </span><span class="lineNoCov">          0 :   luaG_runerror(L, &quot;memory allocation error: block too big&quot;);</span>
<span class="lineNum">      68 </span><span class="lineNoCov">          0 :   return NULL;  /* to avoid warnings */</span>
<span class="lineNum">      69 </span>            : }
<span class="lineNum">      70 </span>            : 
<span class="lineNum">      71 </span>            : 
<span class="lineNum">      72 </span>            : 
<span class="lineNum">      73 </span>            : /*
<span class="lineNum">      74 </span>            : ** generic allocation routine.
<span class="lineNum">      75 </span>            : */
<span class="lineNum">      76 </span><span class="lineCov">     258307 : void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {</span>
<span class="lineNum">      77 </span><span class="lineCov">     258307 :   global_State *g = G(L);</span>
<span class="lineNum">      78 </span>            :   lua_assert((osize == 0) == (block == NULL));
<span class="lineNum">      79 </span><span class="lineCov">     258307 :   block = (*g-&gt;frealloc)(g-&gt;ud, block, osize, nsize);</span>
<span class="lineNum">      80 </span><span class="lineCov">     258307 :   if (block == NULL &amp;&amp; nsize &gt; 0)</span>
<span class="lineNum">      81 </span><span class="lineNoCov">          0 :     luaD_throw(L, LUA_ERRMEM);</span>
<span class="lineNum">      82 </span>            :   lua_assert((nsize == 0) == (block == NULL));
<span class="lineNum">      83 </span><span class="lineCov">     258307 :   g-&gt;totalbytes = (g-&gt;totalbytes - osize) + nsize;</span>
<span class="lineNum">      84 </span><span class="lineCov">     258307 :   return block;</span>
<span class="lineNum">      85 </span>            : }
<span class="lineNum">      86 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
